
package com.seekting.study;

import java.util.Calendar;

public class Timexxx {

    public static void main(String[] args) {
        Calendar calendar=Calendar.getInstance();
        long time1=1402588800000L;
        calendar.setTimeInMillis(time1);
        System.out.println(calendar.getTime().toGMTString());
        
        
        int second = 1000;
        int min = 1000 * 60;
        int hour = min * 60;
        int day = hour * 24;

        long time = System.currentTimeMillis() + day + hour * 24 + min * 1 + second * -1;
        System.out.println(getTimeText(time));
         calendar = Calendar.getInstance();
        calendar.set(2014, 4, 9, 23, 0, 0);
        System.out.println("calendar" + getTimeText(calendar.getTimeInMillis()));

        time = System.currentTimeMillis() + min * 1 + second * -1;
        System.out.println(getTimeText(time));

        time = System.currentTimeMillis() + hour * 1 + min * 0 + second * -1;
        System.out.println(getTimeText(time));
        // System.out.println(Math.round(1.5));

    }

    /**
     * 拿到倒计时的时间
     * 
     * @param gameInfoData
     */
    private static String getTimeText(long time) {
        Calendar currentCalendar = Calendar.getInstance();
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(time);
        if (calendar.get(Calendar.YEAR) == currentCalendar.get(Calendar.YEAR)) {
            // 同一年
            int days = calendar.get(Calendar.DAY_OF_YEAR)
                    - currentCalendar.get(Calendar.DAY_OF_YEAR);

            if (days >= 2) {
                // 大于两天就说有多少天
                return days + "天后";

            } else {
                long times = calendar.getTimeInMillis() - currentCalendar.getTimeInMillis();

                long oneHour = 1000 * 60 * 60;
                long oneMinute = 1000 * 60;
                if (times < oneMinute) {
                    return "即将开始";
                }
                else if (times < oneHour) {
                    float minutes = (times * 1f) / oneMinute;
                    return Math.round(minutes) + "分钟后";
                } else {
                    float hours = (times * 1f) / oneHour;
                    return Math.round(hours) + "小时后";
                }

            }
        }

        return "";

    }
}
